package com.dfy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dfy.entity.UserFavorite;
import com.dfy.entity.Spot;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserFavoriteMapper extends BaseMapper<UserFavorite> {
    @Delete("DELETE FROM user_favorites WHERE user_id = #{userId} AND spot_id = #{spotId}")
    int deleteByUserIdAndSpotId(@Param("userId") Long userId, @Param("spotId") Long spotId);

    @Select("SELECT s.* FROM spots s " +
           "JOIN user_favorites uf ON s.id = uf.spot_id " +
           "WHERE uf.user_id = #{userId}")
    List<Spot> getUserFavoriteSpots(@Param("userId") Long userId);

    @Delete("DELETE FROM user_favorites WHERE spot_id = #{spotId}")
    int deleteBySpotId(@Param("spotId") Long spotId);
} 